Commit 67039f6b authored by sumpfralle's avatar sumpfralle

separated the ProgressCounter class


git-svn-id: https://pycam.svn.sourceforge.net/svnroot/pycam/trunk@372 bbaffbd6-741e-11dd-a85d-61de82d9cad9
parent cb487d92
...@@ -23,29 +23,16 @@ along with PyCAM. If not, see <http://www.gnu.org/licenses/>. ...@@ -23,29 +23,16 @@ along with PyCAM. If not, see <http://www.gnu.org/licenses/>.
from pycam.Geometry import Point from pycam.Geometry import Point
from pycam.Geometry.utils import INFINITE, epsilon from pycam.Geometry.utils import INFINITE, epsilon
from pycam.PathGenerators import drop_cutter_test, get_free_horizontal_paths_ode, get_free_horizontal_paths_triangles from pycam.PathGenerators import drop_cutter_test, get_free_horizontal_paths_ode, get_free_horizontal_paths_triangles, ProgressCounter
import math import math
class ProgressCounter:
def __init__(self, max_value):
self.max_value = max_value
self.current_value = 0
def next(self):
self.current_value += 1
def get_percent(self):
return 100.0 * self.current_value / self.max_value
class PushCutter: class PushCutter:
def __init__(self, cutter, model, pathextractor=None, physics=None): def __init__(self, cutter, model, path_processor, physics=None):
self.cutter = cutter self.cutter = cutter
self.model = model self.model = model
self.pa = pathextractor self.pa = path_processor
self.physics = physics self.physics = physics
def GenerateToolPath(self, minx, maxx, miny, maxy, minz, maxz, dx, dy, dz, draw_callback=None): def GenerateToolPath(self, minx, maxx, miny, maxy, minz, maxz, dx, dy, dz, draw_callback=None):
...@@ -63,9 +50,8 @@ class PushCutter: ...@@ -63,9 +50,8 @@ class PushCutter:
dy = abs(maxy - miny) / (y_lines_per_layer - 1) dy = abs(maxy - miny) / (y_lines_per_layer - 1)
lines_per_layer += y_lines_per_layer lines_per_layer += y_lines_per_layer
progress_counter = ProgressCounter(num_of_layers * lines_per_layer) progress_counter = ProgressCounter(num_of_layers * lines_per_layer,
draw_callback)
z = maxz
paths = [] paths = []
...@@ -91,6 +77,7 @@ class PushCutter: ...@@ -91,6 +77,7 @@ class PushCutter:
self.pa.end_direction() self.pa.end_direction()
self.pa.finish() self.pa.finish()
# the path accumulator will be reset for each slice - we need to store the result
if self.pa.paths: if self.pa.paths:
paths += self.pa.paths paths += self.pa.paths
...@@ -148,7 +135,5 @@ class PushCutter: ...@@ -148,7 +135,5 @@ class PushCutter:
# update the progress counter # update the progress counter
if not progress_counter is None: if not progress_counter is None:
progress_counter.next() progress_counter.increment()
if draw_callback:
draw_callback(percent=progress_counter.get_percent())
...@@ -20,13 +20,29 @@ You should have received a copy of the GNU General Public License ...@@ -20,13 +20,29 @@ You should have received a copy of the GNU General Public License
along with PyCAM. If not, see <http://www.gnu.org/licenses/>. along with PyCAM. If not, see <http://www.gnu.org/licenses/>.
""" """
__all__ = ["DropCutter", "PushCutter"] __all__ = ["DropCutter", "PushCutter", "EngraveCutter"]
from pycam.Geometry.utils import INFINITE, epsilon from pycam.Geometry.utils import INFINITE, epsilon
from pycam.Geometry import Point from pycam.Geometry import Point
import math import math
class ProgressCounter:
def __init__(self, max_value, update_callback):
self.max_value = max_value
self.current_value = 0
self.update_callback = update_callback
def increment(self):
self.current_value += 1
if self.update_callback:
self.update_callback(percent=self.get_percent())
def get_percent(self):
return 100.0 * self.current_value / self.max_value
class Hit: class Hit:
def __init__(self, cl, t, d, dir): def __init__(self, cl, t, d, dir):
self.cl = cl self.cl = cl
...@@ -229,6 +245,7 @@ def get_max_height_ode(physics, x, y, minz, maxz, order=None): ...@@ -229,6 +245,7 @@ def get_max_height_ode(physics, x, y, minz, maxz, order=None):
return [Point(x, y, safe_z)] return [Point(x, y, safe_z)]
def get_max_height_triangles(model, cutter, x, y, minz, maxz, order=None, last_pos=None): def get_max_height_triangles(model, cutter, x, y, minz, maxz, order=None, last_pos=None):
# TODO: "order" should be replaced with a direction vector
result = [] result = []
if last_pos is None: if last_pos is None:
last_pos = {} last_pos = {}
......
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