Commit 0b20d91c authored by sumpfralle's avatar sumpfralle

added "merge regardless of direction" to "Revise directions" operation


git-svn-id: https://pycam.svn.sourceforge.net/svnroot/pycam/trunk@1019 bbaffbd6-741e-11dd-a85d-61de82d9cad9
parent b039ec78
...@@ -8150,7 +8150,7 @@ Any selected group of dimensions will be scaled accordingly.</property> ...@@ -8150,7 +8150,7 @@ Any selected group of dimensions will be scaled accordingly.</property>
<property name="step_increment">1</property> <property name="step_increment">1</property>
</object> </object>
<object class="GtkAction" id="OpenRecentModel"> <object class="GtkAction" id="OpenRecentModel">
<property name="label">Open _Recent Model</property> <property name="label">Open _Recent</property>
<property name="stock_id">gtk-open</property> <property name="stock_id">gtk-open</property>
<property name="always_show_image">True</property> <property name="always_show_image">True</property>
</object> </object>
......
...@@ -322,7 +322,7 @@ class ContourModel(BaseModel): ...@@ -322,7 +322,7 @@ class ContourModel(BaseModel):
# reset the offset model cache # reset the offset model cache
self._cached_offset_models = {} self._cached_offset_models = {}
def _merge_polygon_if_possible(self, other_polygon): def _merge_polygon_if_possible(self, other_polygon, allow_reverse=False):
""" Check if the given 'other_polygon' can be connected to another """ Check if the given 'other_polygon' can be connected to another
polygon of the the current model. Both polygons are merged if possible. polygon of the the current model. Both polygons are merged if possible.
This function should be called after any "append" event, if the lines to This function should be called after any "append" event, if the lines to
...@@ -354,9 +354,23 @@ class ContourModel(BaseModel): ...@@ -354,9 +354,23 @@ class ContourModel(BaseModel):
for line in lines: for line in lines:
other_polygon.append(line) other_polygon.append(line)
self._line_groups.remove(polygon) self._line_groups.remove(polygon)
elif allow_reverse:
if other_polygon.get_points()[-1] == polygon.get_points()[-1]:
polygon.reverse_direction()
for line in polygon.get_lines():
other_polygon.append(line)
self._line_groups.remove(polygon)
elif other_polygon.get_points()[0] == polygon.get_points()[0]:
polygon.reverse_direction()
lines = polygon.get_lines()
lines.reverse()
for line in lines:
other_polygon.append(line)
self._line_groups.remove(polygon)
else:
pass
else: else:
log.debug("merge_polygon_if_possible: ambiguous combinations " \ pass
+ "(%s - %s)" % (other_polygon, connectables))
def append(self, item, unify_overlaps=False, allow_reverse=False): def append(self, item, unify_overlaps=False, allow_reverse=False):
super(ContourModel, self).append(item) super(ContourModel, self).append(item)
...@@ -369,7 +383,8 @@ class ContourModel(BaseModel): ...@@ -369,7 +383,8 @@ class ContourModel(BaseModel):
for candidate in item_list: for candidate in item_list:
if line_group.is_connectable(candidate): if line_group.is_connectable(candidate):
line_group.append(candidate) line_group.append(candidate)
self._merge_polygon_if_possible(line_group) self._merge_polygon_if_possible(line_group,
allow_reverse=allow_reverse)
found = True found = True
break break
if found: if found:
...@@ -448,10 +463,33 @@ class ContourModel(BaseModel): ...@@ -448,10 +463,33 @@ class ContourModel(BaseModel):
else: else:
return [group for group in self._line_groups if group.minz <= z] return [group for group in self._line_groups if group.minz <= z]
def detect_directions(self, callback=None): def revise_directions(self, callback=None):
""" Go through all open polygons and try to merge them regardless of
their direction. Afterwards all closed polygons are analyzed regarding
their inside/outside relationships.
Beware: never use this function if the direction of lines may not
change.
"""
# try to connect all open polygons
open_polygons = [poly for poly in self.get_polygons()
if not poly.is_closed]
for poly in open_polygons:
self._line_groups.remove(poly)
poly_open_before = len(open_polygons)
for poly in open_polygons:
for line in poly.get_lines():
self.append(line, allow_reverse=True)
poly_open_after = len([poly for poly in self.get_polygons()
if not poly.is_closed])
if poly_open_before != poly_open_after:
log.info("Reduced the number of open polygons from " + \
"%d down to %d" % (poly_open_before, poly_open_after))
else:
log.debug("No combineable open polygons found")
# auto-detect directions of closed polygons: inside and outside
finished = [] finished = []
# handle only closed polygons remaining_polys = [poly for poly in self.get_polygons()
remaining_polys = [poly for poly in self.get_polygons() if poly.is_closed] if poly.is_closed]
if callback: if callback:
progress_callback = pycam.Utils.ProgressCounter( progress_callback = pycam.Utils.ProgressCounter(
2 * len(remaining_polys), callback).increment 2 * len(remaining_polys), callback).increment
......
...@@ -2916,7 +2916,7 @@ class ProjectGui: ...@@ -2916,7 +2916,7 @@ class ProjectGui:
return return
self._store_undo_state() self._store_undo_state()
self.update_progress_bar(text="Analyzing directions of contour model") self.update_progress_bar(text="Analyzing directions of contour model")
self.model.detect_directions(callback=self.update_progress_bar) self.model.revise_directions(callback=self.update_progress_bar)
self.update_support_model() self.update_support_model()
@progress_activity_guard @progress_activity_guard
......
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