Commit 6b2570c4 authored by sumpfralle's avatar sumpfralle

don't run gtk's "main_iteration" more than once per second (improves performance)

fixed typo
fixed another floating point inaccuracy issue
replaced full function definitions for "ceil", "sqrt" and "number" with lambda inline functions


git-svn-id: https://pycam.svn.sourceforge.net/svnroot/pycam/trunk@723 bbaffbd6-741e-11dd-a85d-61de82d9cad9
parent 5f1a3d10
...@@ -30,25 +30,22 @@ epsilon = 0.00001 ...@@ -30,25 +30,22 @@ epsilon = 0.00001
_use_precision = False _use_precision = False
def sqrt(value): # the lambda functions below are more efficient than function definitions
# support precision libraries like "decimal" (built-in)
if -epsilon < value <= 0: if _use_precision:
# compensate slightly negative values (due to float inaccuracies) ceil = lambda value: int((value + number(1).next_minus()) // 1)
return 0 else:
if hasattr(value, "sqrt"): ceil = lambda value: int(math.ceil(value))
return value.sqrt()
else: # return "0" for "-epsilon < value < 0" (to work around floating inaccuracies)
return math.sqrt(value) # otherwise: return the sqrt function of the current type (could even raise exceptions)
if _use_precision:
def ceil(value): sqrt = lambda value: (((value < -epsilon) or (value > 0)) and value.sqrt()) or 0
if hasattr(value, "next_minus"): else:
return int((value + number(1).next_minus()) // 1) sqrt = lambda value: (((value < -epsilon) or (value > 0)) and math.sqrt(value)) or 0
else:
return int(math.ceil(value)) if _use_precision:
number = lambda value: decimal.Decimal(str(value))
def number(value): else:
if _use_precision: number = lambda value: value
return decimal.Decimal(str(value))
else:
return float(value)
...@@ -174,6 +174,7 @@ class ProjectGui: ...@@ -174,6 +174,7 @@ class ProjectGui:
self._batch_queue = [] self._batch_queue = []
self._progress_running = False self._progress_running = False
self._progress_cancel_requested = False self._progress_cancel_requested = False
self._last_gtk_events_time = None
self.gui = gtk.Builder() self.gui = gtk.Builder()
gtk_build_file = get_data_file_location(GTKBUILD_FILE) gtk_build_file = get_data_file_location(GTKBUILD_FILE)
if gtk_build_file is None: if gtk_build_file is None:
...@@ -2621,8 +2622,15 @@ class ProjectGui: ...@@ -2621,8 +2622,15 @@ class ProjectGui:
lines.append(eta_text) lines.append(eta_text)
self.progress_bar.set_text(os.linesep.join(lines)) self.progress_bar.set_text(os.linesep.join(lines))
# update the GUI # update the GUI
while gtk.events_pending(): current_time = time.time()
gtk.main_iteration() # Don't update the GUI more often than once per second.
# This restriction improves performance and reduces the
# "snappiness" of the GUI.
if (self._last_gtk_events_time is None) \
or (self._last_gtk_events_time + 1 < current_time):
while gtk.events_pending():
gtk.main_iteration()
self._last_gtk_events_time = current_time
# return if the user requested a break # return if the user requested a break
return self._progress_cancel_requested return self._progress_cancel_requested
...@@ -2897,7 +2905,7 @@ class ProjectGui: ...@@ -2897,7 +2905,7 @@ class ProjectGui:
if filename_templates is None: if filename_templates is None:
valid_templates = [] valid_templates = []
else: else:
valid_templates = [t for t in filename_templates if one_template] valid_templates = [t for t in filename_templates if t]
if valid_templates: if valid_templates:
filename_template = valid_templates[0] filename_template = valid_templates[0]
# remove the extension # remove the extension
......
...@@ -206,7 +206,7 @@ class ContourFollow: ...@@ -206,7 +206,7 @@ class ContourFollow:
# collision handling function # collision handling function
for z in z_steps: for z in z_steps:
# update the progress bar and check, if we should cancel the process # update the progress bar and check, if we should cancel the process
if draw_callback and draw_callback(text="PushCutter: processing" \ if draw_callback and draw_callback(text="ContourFollow: processing" \
+ " layer %d/%d" % (current_layer + 1, num_of_layers)): + " layer %d/%d" % (current_layer + 1, num_of_layers)):
# cancel immediately # cancel immediately
break break
...@@ -353,6 +353,9 @@ class ContourFollow: ...@@ -353,6 +353,9 @@ class ContourFollow:
# This is just an accuracy issue (see the # This is just an accuracy issue (see the
# "triangle.minz >= z" statement above). # "triangle.minz >= z" statement above).
outer_edges = [] outer_edges = []
elif not [p for p in triangle.get_points() if p.z > z + epsilon]:
# same as above: fix for inaccurate floating calculations
outer_edges = []
else: else:
# this should not happen # this should not happen
raise ValueError(("Could not find a waterline, but " \ raise ValueError(("Could not find a waterline, but " \
......
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