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
_use_precision = False
def sqrt(value):
# support precision libraries like "decimal" (built-in)
if -epsilon < value <= 0:
# compensate slightly negative values (due to float inaccuracies)
return 0
if hasattr(value, "sqrt"):
return value.sqrt()
else:
return math.sqrt(value)
def ceil(value):
if hasattr(value, "next_minus"):
return int((value + number(1).next_minus()) // 1)
else:
return int(math.ceil(value))
def number(value):
if _use_precision:
return decimal.Decimal(str(value))
else:
return float(value)
# the lambda functions below are more efficient than function definitions
if _use_precision:
ceil = lambda value: int((value + number(1).next_minus()) // 1)
else:
ceil = lambda value: int(math.ceil(value))
# return "0" for "-epsilon < value < 0" (to work around floating inaccuracies)
# otherwise: return the sqrt function of the current type (could even raise exceptions)
if _use_precision:
sqrt = lambda value: (((value < -epsilon) or (value > 0)) and value.sqrt()) or 0
else:
sqrt = lambda value: (((value < -epsilon) or (value > 0)) and math.sqrt(value)) or 0
if _use_precision:
number = lambda value: decimal.Decimal(str(value))
else:
number = lambda value: value
......@@ -174,6 +174,7 @@ class ProjectGui:
self._batch_queue = []
self._progress_running = False
self._progress_cancel_requested = False
self._last_gtk_events_time = None
self.gui = gtk.Builder()
gtk_build_file = get_data_file_location(GTKBUILD_FILE)
if gtk_build_file is None:
......@@ -2621,8 +2622,15 @@ class ProjectGui:
lines.append(eta_text)
self.progress_bar.set_text(os.linesep.join(lines))
# update the GUI
current_time = time.time()
# 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 self._progress_cancel_requested
......@@ -2897,7 +2905,7 @@ class ProjectGui:
if filename_templates is None:
valid_templates = []
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:
filename_template = valid_templates[0]
# remove the extension
......
......@@ -206,7 +206,7 @@ class ContourFollow:
# collision handling function
for z in z_steps:
# 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)):
# cancel immediately
break
......@@ -353,6 +353,9 @@ class ContourFollow:
# This is just an accuracy issue (see the
# "triangle.minz >= z" statement above).
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:
# this should not happen
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